#!/bin/sh

# SYS_BYTEORDER=IS_LITTLE_ENDIAN
# export SYS_BYTEORDER

CC=gcc
AR=ar
LIBCC_ROOT=$(pwd)

LIBCC_STL=$LIBCC_ROOT/lib/libcc_stl.a
LIBCC_NET=$LIBCC_ROOT/lib/libcc_net.a
LIBCC_NETIO=$LIBCC_ROOT/lib/libcc_netio.a
LIBCC_BYTEORDER=__CC_LITTLE_ENDIAN

export CC
export AR
export LIBCC_ROOT
export LIBCC_STL
export LIBCC_NET
export LIBCC_BYTEORDER
export LIBCC_NETIO

function build_libcc_net(){
    cd $LIBCC_ROOT/libcc_net/src
    make clean && make
    return $?
}

function build_libcc_netio()
{
    right=0
    if [ $1 = "x86" ]
    then
        right=1
    fi
    
    if [ $right -gt 0 ]
    then
        cd $LIBCC_ROOT/libcc_netio/src_$1
    else
        echo "Unknown platform!"
    fi
    
    make clean && make
    
    return $?
}

function build_libcc_stl()
{
    cd $LIBCC_ROOT/libcc_stl/src
    make clean && make
    
    #cd $LIBCC_ROOT/libcc_stl/test
    #make clean && make
    return $?
}

################################### main ###############################
case $1 in 
    "stl") 
        build_libcc_stl
        ;;
    "net")
        build_libcc_net
        ;;
    "netio")
        build_libcc_netio $2
        ;;
    "ddos")
        cd $LIBCC_ROOT/ddos && make clean && make
        ;;
    *)
        echo "unknown build options"
        ;;
esac
